/**
 * nghilt
 * 2011/09/26
 */
package at.com.vn.chess.entity;

import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;

import vn.nnn.shogi.quanco.QuanCo;
import at.com.vn.chess.util.CommonMethod;
import at.com.vn.chess.util.Const;

/**
 *
 */
@XmlRootElement(name="boardInfo")
public class ChessBoardInfo implements Entity {

	private String processName;
	private int rId;
	private int tId;
	
	private String uId;
	private String chatMsg;
	private boolean isAct;
	private boolean isDeleted;
	private boolean isTOwner;

	private String status;

	private int turn;
	private int whosWon;
	private String bName;
	private String wName;
	private int bRemainT;
	private int wRemainT;

	private List<ChessInfo> listChessInfo;

	public ChessBoardInfo() {
		super();

		this.uId = "";
		this.chatMsg = "";
		this.isAct = false;
		this.isDeleted = false;
		this.isTOwner = false;


		this.status = Const.STATUS_IDLE;
		this.turn = Const.UNDEFINE_VALUE;
		this.whosWon = Const.UNDEFINE_VALUE;

		this.bName = "";
		this.wName = "";
		this.bRemainT = 0;
		this.wRemainT = 0;

		this.listChessInfo = new ArrayList<ChessInfo>();
	}

	public ChessBoardInfo(String status, int turn, int whosWon, ChatUser user, List<QuanCo> listQuanCo ) {
		this();
		this.uId = user.getUserID();
		this.chatMsg = user.getChatMsg();
		if(user.isActive == Const.TRUE) {
			this.isAct = true;
		}else {
			this.isAct = false;
		}
		if(user.isActive == Const.TRUE) {
			this.isDeleted = true;
		}else {
			this.isDeleted = false;
		}
		rId = Integer.parseInt(user.getRoomID());
		tId = user.getPrivateRoomID();

		this.status = status;
		this.turn = turn;
		this.whosWon = whosWon;

		ChessInfo info;
		for(QuanCo quanCo : listQuanCo) {
			info = new ChessInfo(quanCo);
			this.listChessInfo.add(info);
		}
	}

	public ChessBoardInfo(String status, int turn, String blackName, String whiteName,
			int blackRemainTime, int whiteRemainTime, int whosWon, ChatUser user,
			boolean isTablesOwner, List<QuanCo> listQuanCo ) {
		this(status, turn, whosWon, user, listQuanCo);

		this.bName = blackName;
		this.wName = whiteName;
		this.bRemainT = blackRemainTime;
		this.wRemainT = whiteRemainTime;

		this.isTOwner = isTablesOwner;
	}

	public String getUId() {
		return uId;
	}

	public void setUId(String uId) {
		this.uId = uId;
	}

	public String getChatMsg() {
		return chatMsg;
	}

	public void setChatMsg(String chatMsg) {
		this.chatMsg = chatMsg;
	}

	public boolean getIsAct() {
		return isAct;
	}

	public void setIsAct(boolean isAct) {
		this.isAct = isAct;
	}

	public boolean getIsDeleted() {
		return isDeleted;
	}

	public void setIsDeleted(boolean isDeleted) {
		this.isDeleted = isDeleted;
	}

	public boolean getIsTOwner() {
		return isTOwner;
	}

	public void setIsTOwner(boolean isTOwner) {
		this.isTOwner = isTOwner;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public int getTurn() {
		return turn;
	}

	public void setTurn(int turn) {
		this.turn = turn;
	}

	public int getWhosWon() {
		return whosWon;
	}

	public void setWhosWon(int whosWon) {
		this.whosWon = whosWon;
	}

	public String getBName() {
		return bName;
	}

	public void setBName(String bName) {
		this.bName = bName;
	}

	public String getWName() {
		return wName;
	}

	public void setWName(String wName) {
		this.wName = wName;
	}

	public int getBRemainT() {
		return bRemainT;
	}

	public void setBRemainT(int bRemainT) {
		this.bRemainT = bRemainT;
	}

	public int getWRemainT() {
		return wRemainT;
	}

	public void setWRemainT(int wRemainT) {
		this.wRemainT = wRemainT;
	}

	public List<ChessInfo> getListChessInfo() {
		return listChessInfo;
	}

	public void setListChessInfo(List<ChessInfo> listChessInfo) {
		this.listChessInfo = listChessInfo;
	}

	public static void main(String[] args) {
		List<ChessInfo> list = new ArrayList<ChessInfo>();
		ChessInfo info;
		for (int i = 0; i < 40; i++) {
			info = new ChessInfo();
			info.setName("QuanHuongXaPhongCap" + i);
			list.add(info);
		}
//		ChessBoardInfo chessInfo = new ChessBoardInfo();
//		chessInfo.setrId(1);
//		chessInfo.setListChessInfo(list);
//		String xml = XmlUtils.convertToXml(chessInfo, "PlayShogi");
//		System.out.println(xml);
//		System.out.println(xml.length());
//		System.out.println(XmlUtils.getProcessName(xml));
	}

	@Override
	public String toString() {
		return "ChessBoardInfo [uId=" + uId + ", chatMsg=" + chatMsg
				+ ", isAct=" + isAct + ", isDeleted=" + isDeleted
				+ ", isTOwner=" + isTOwner + ", status=" + status + ", turn="
				+ turn + ", whosWon=" + whosWon + ", bName=" + bName
				+ ", wName=" + wName + ", bRemainT=" + bRemainT + ", wRemainT="
				+ wRemainT + ", listChessInfo=" + listChessInfo + "]";
	}

	@Override
	public String getProcessName() {
		return processName;
	}

	@Override
	public void setProcessName(String processName) {
		this.processName = processName;
		
	}

	@Override
	public boolean isOwnTable(int room, int table) {		
		return rId == room && tId == table;
	}

	@Override
	public String getBoardsKey() {		
		return CommonMethod.createBoardKey(rId, tId);
	}

	public int getRId() {
		return rId;
	}

	public void setRId(int rId) {
		this.rId = rId;
	}

	public int getTId() {
		return tId;
	}

	public void setTId(int tId) {
		this.tId = tId;
	}
	
}
